package com.shsxt.crm.controller.sys;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shsxt.common.util.Result;
import com.shsxt.crm.model.YgRole;
import com.shsxt.crm.service.ISystemRoleService;
import com.shsxt.framework.context.BaseController;

/**
 * 用户信息管理
 * 
 * @author Mr.YongGan.Zhang
 */

@Controller
@RequestMapping("/sysrole")
public class SystemRoleController extends BaseController {

	@Autowired
	private ISystemRoleService systemRoleService;

	@GetMapping("index.shtml")
	public String index() {
		return "role";
	}

	@PostMapping("/queryAllRoles")
	@ResponseBody
	public List<YgRole> queryAllRoles() {
		return systemRoleService.queryAllRoles(null);
	}

	@PostMapping("/queryAllRolesByParams")
	@ResponseBody
	public Map<String, Object> queryAllRolesByParams(String roleName,
			@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		return systemRoleService.queryAllRolesByParams(roleName, page, rows);
	}

	@PostMapping("/insert")
	@ResponseBody
	public Result insertSysRole(YgRole ygRole) {
		return systemRoleService.insertSysRole(ygRole);
	}

	@PostMapping("/update")
	@ResponseBody
	public Result updateSysRole(YgRole ygRole) {
		return systemRoleService.updateSysRole(ygRole);
	}

	/**
	 * 需要大家一起来修复 为批量删除
	 * 
	 * @param ids
	 * @return
	 */
	@PostMapping("/delete")
	@ResponseBody
	public Result delSysRole(Integer[] ids) {
		return systemRoleService.delSysRole(ids[0]);
	}

	/**
	 * 角色授权
	 * 
	 * @return
	 */
	@PostMapping("/addPermission")
	@ResponseBody
	public Result addPermission(Integer rid, Integer[] moduleIds) {
		return systemRoleService.addPermission(rid, moduleIds);
	}

}
